package com.youkeda.yikao.web.control;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.ArrayList;
import java.util.List;

public class CountControl implements HttpSessionListener {
    //可以用数据库进行替换
    private final List<String>ids=new ArrayList<>();
    @Override
    public void sessionCreated(HttpSessionEvent se) {
      String id=se.getSession().getId();
      ids.add(id);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        String id=se.getSession().getId();
        ids.remove(id);

    }
    @RequestMapping("/session/count")
    public int count(){
        return ids.size();
    }
}
